package com.excesys.exsecs.eco.controller;


import cn.hutool.core.util.ObjectUtil;
import cn.hutool.json.JSONObject;
import com.excesys.exsecs.common.core.util.R;
import com.excesys.exsecs.common.security.annotation.Inner;
import com.excesys.exsecs.eco.service.EcoEfficiencyAnalyseService;
import com.excesys.exsecs.eco.service.EcoPowerHourFlowService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpHeaders;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Objects;

/**
 * 能效分析接口
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/ecoEfficiencyAnalyse")
@Tag(description = "ecoEfficiencyAnalyse", name = "能效分析")
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
public class EcoEfficiencyAnalyseController {


    private final EcoEfficiencyAnalyseService ecoEfficiencyAnalyseService;
	private final EcoPowerHourFlowService powerHourFlowService;

    /**
     * 总/平均用电量、冷量、COP
     *
     * @param startTime
     * @param endTime
     * @return
     */
    @Operation(summary = "总/平均用电量、冷量、COP", description = "总/平均用电量、冷量、COP")
    @GetMapping("/getTopData")
    @Inner(value = false)
    public R top(String startTime, String endTime) {
        return R.ok(ecoEfficiencyAnalyseService.getCopData(startTime, endTime), "总/平均用电量、冷量、COP/列表");
    }

    /**
     * 总/平均用电量、冷量、COP 列表 与图层
     *
     * @param startTime
     * @param endTime
     * @return
     */
    @Operation(summary = "总/平均用电量、冷量、COP", description = "总/平均用电量、冷量、COP")
    @GetMapping("/getTopList")
    @Inner(value = false)
    public R getTopList(String startTime, String endTime) {
        return R.ok(ecoEfficiencyAnalyseService.getCopList(startTime, endTime), "总/平均用电量、冷量、COP/列表");
    }

	/**
	 * 能耗查询
	 * @param startTime
	 * @param endTime
	 * @return
	 */
	@Operation(summary = "能耗查询" , description = "能耗查询" )
	@GetMapping("/energyQuery")
	public R energyQuery(String startTime,String endTime){
		return R.ok(powerHourFlowService.energyQuery(startTime,endTime),"能耗查询");
	}

	@Operation(summary = "查询电能分析详细报表", description = "查询电能分析详细报表")
	@GetMapping("/getElectricalEnergyList")
	public R getElectricalEnergyList(String startDate, String endDate,@RequestParam List<String> idList) {
		if (Objects.isNull(startDate) || Objects.isNull(endDate)) {
			return R.failed("请输入开始时间和结束时间");
		}
		return R.ok(powerHourFlowService.getElectricalEnergyList(startDate, endDate, idList));
	}

	/**
	 * 能耗计量
	 * @param startTime
	 * @param endTime
	 * @return
	 */
	@Operation(summary = "能耗计量" , description = "能耗计量" )
	@GetMapping("/energyMeasure")
	public R energyMeasure(String startTime,String endTime){
		return R.ok(powerHourFlowService.energyMeasure(startTime,endTime));
	}


}
